package cn.butcher21.controller;

import cn.butcher21.dao.DaoWork;
import cn.butcher21.dao.DaoWorkImpl.DaoWorkImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "GetTeacherEvaluateServlet", value = "/getTeacherEvaluate")
public class GetTeacherEvaluateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String userid = (String) request.getSession().getAttribute("userid");
        DaoWork daoWork = new DaoWorkImpl();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, String> map = null;
        try {
            map = daoWork.getTeacherEvaluateMsg(userid, sdf.format(new Date()));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Gson gson = new Gson();
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print(gson.toJson(map));

    }
}
